package com.DHH.Service.Api;

import com.DHH.Entity.Base.BaseUser;
import com.DHH.Entity.Identity.IdentityAuthentication;
import com.DHH.Entity.Identity.IdentityAuthenticationRecord;
import com.DHH.Entity.Identity.IdentityAuthenticationState;
import com.DHH.Mapper.Identity.IdentityAuthenticationMapper;
import com.DHH.Mapper.Identity.IdentityAuthenticationRecordMapper;
import com.DHH.Mapper.Identity.IdentityAuthenticationStateMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by 汪玉东 on 2017/8/8.
 */
@Service
public class ApiIdentityAuthServicesImpl  implements  ApiIdentityAuthServices{
    @Resource
    private IdentityAuthenticationMapper identityAuthenticationMapper;
    @Resource
    private IdentityAuthenticationRecordMapper identityAuthenticationRecordMapper;
    @Resource
    private IdentityAuthenticationStateMapper identityAuthenticationStateMapper;

    @Override
    public boolean insert(IdentityAuthentication identityAuthentication, BaseUser baseUser) {

        IdentityAuthenticationState identityAuthenticationState=new IdentityAuthenticationState();
        identityAuthenticationState.setStatesMark("dsh");
        identityAuthenticationState=identityAuthenticationStateMapper.selectOne(identityAuthenticationState);


        identityAuthentication.setUserId(baseUser.getId());
        identityAuthentication.setStateId(identityAuthenticationState.getId());
        identityAuthentication.setCreateTime(new Date());
        identityAuthenticationMapper.insert(identityAuthentication);
        if(identityAuthentication.getId()==null){
            return false;
        }

        IdentityAuthenticationRecord identityAuthenticationRecord=new IdentityAuthenticationRecord();
        identityAuthenticationRecord.setAuthenticationId(identityAuthentication.getId());
        identityAuthenticationRecord.setStateId(identityAuthenticationState.getId());
        identityAuthenticationRecord.setMsg("上传资料待审核");
        identityAuthenticationRecord.setOperateId(baseUser.getId());
        identityAuthenticationRecord.setOperateTime(new Date());
        identityAuthenticationRecordMapper.insert(identityAuthenticationRecord);
        return true;
    }

}
